<template>
    <h2>用户登录</h2>
    <table class="table table-bordered">
        <tr>
            <td>用户名：</td>
            <td><input type="text" v-model="info.name"></td>
        </tr>
        <tr>
            <td>密码：</td>
            <td><input type="password" v-model="info.pwd"></td>
        </tr>
        <tr>
            <td colspan="2"><button @click="login">登录</button></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useRouter, useRoute} from 'vue-router';
import axios from 'axios';
import { useStore } from '../../store/index.ts';


const store = useStore();
const router = useRouter();
const route = useRoute();

const info = ref({
    name: '',
    pwd: ''
});


const login = () => {
    if(info.value.name=="")
    {
        alert("用户名不能为空！")
        return; 
    }
    if(info.value.pwd=="")
    {
        alert("密码不能为空！")
        return; 
    }
    
   
    //发送请求

    axios({
        method: 'get',
        url: 'http://localhost:61498/api/UserInAll/Login',
        params: info.value
    })
    .then(res => {
        
        console.log(res.data)
        if(res.data.length==0)
        {
            alert("登录失败！")
            
          
        }
        else {
            alert("登录成功")
            store.Uid=res.data[0].Uid;
            alert(store.Uid)
            router.push('/AddUser');
        }
    })
    .catch(err => {
        console.log(err);
    })
}
</script>